<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class checkuplog_class extends CI_Model {
	
		public function insert($post) {
			$intUserID = stripslashes(filter_var($post['intUserID'], FILTER_SANITIZE_STRING));
			$strNoteTitle = stripslashes(filter_var($post['strNoteTitle'], FILTER_SANITIZE_STRING));
			$dateNoteDate = stripslashes(filter_var($post['dateNoteDate'], FILTER_SANITIZE_STRING));
			$strNotes = $post['strNotes'];

			$data = array(
			'intUserID' => $intUserID, 
			'strNoteTitle' => $strNoteTitle, 
			'dateNoteDate' => $dateNoteDate, 
			'strNotes' => $strNotes,
			'intDisabled' => 0,
			'strCreatedby'=>$this->session->userdata('intID'),
			'dateCreatedDate'=>date('Y-m-d H:i:s'),
			'strModifiedBy'=>$this->session->userdata('intID'),
			'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			
			$this->db->insert('jtn_checkuplog', $data); 
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0) {
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			} else {
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;			
			}
			return $message;			
		}
		public function get_checkuplog($post){
			$intID=0;
			if(isset($post['intID'])){
				$intID = $post['intID'];
			}
			$intID = stripslashes(filter_var($intID, FILTER_SANITIZE_STRING));
			$query = $this->db->get_where('jtn_checkuplog',array('intID'=>$intID))->result_array();
			$query = current($query);
			
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function update($post) {
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$strNoteTitle = stripslashes(filter_var($post['strNoteTitle'], FILTER_SANITIZE_STRING));
			$dateNoteDate = stripslashes(filter_var($post['dateNoteDate'], FILTER_SANITIZE_STRING));
			$strNotes = $post['strNotes'];			
		
			$data = array(
					'strNoteTitle' => $strNoteTitle,
					'dateNoteDate' => $dateNoteDate,
					'strNotes' => $strNotes,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
				
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_checkuplog', $data);
				
			if($this->db->_error_number()==0) {
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			} else {
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}	
		public function delete($post) {
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
		
			$data = array(
					'intDisabled' => 1,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
		
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_checkuplog', $data);
		
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully deleted.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function list_checkuplog($post){
			if(isset($post['intUserID'])){
				$intUserID = stripslashes(filter_var($post['intUserID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intUserID'=>$intUserID));
			}
			
			$this->db->order_by("dateNoteDate", "asc");
			$query = $this->db->get_where('jtn_checkuplog',array('intDisabled'=>0));
			if ($query->num_rows() > 0)	{
				$result = $query->result_array();
				return $result;
			} else {
				return 0;
			}
		}
	} // end class
?>